﻿namespace Nomo.PathFindingModule
{
    /// <summary>
    /// 网格。
    /// </summary>
    public class Grid : System.ICloneable
    {
        /// <summary>
        /// 行坐标。
        /// </summary>
        public int RowIndex = -1;

        /// <summary>
        /// 列坐标。
        /// </summary>
        public int ColumnIndex = -1;

        /// <summary>
        /// 是否可通行？
        /// </summary>
        public bool Walkable = true;

        /// <summary>
        /// 上一个网格。
        /// </summary>
        public Grid From;

        /// <summary>
        /// 从起点网格到这个网格的精确代价。
        /// </summary>
        public double G;

        /// <inheritdoc />
        public virtual object Clone()
        {
            return new Grid
            {
                RowIndex    = RowIndex,
                ColumnIndex = ColumnIndex,
                Walkable    = Walkable,
                From        = From
            };
        }
    }

    /// <summary>
    /// 可携带数据的网格。
    /// </summary>
    /// <typeparam name="T">携带的数据。</typeparam>
    public sealed class Grid<T> : Grid
    {
        /// <summary>
        /// 携带的数据。
        /// </summary>
        public T Value;

        /// <inheritdoc />
        public override object Clone()
        {
            return new Grid<T>
            {
                RowIndex    = RowIndex,
                ColumnIndex = ColumnIndex,
                Walkable    = Walkable,
                From        = From,
                Value       = Value
            };
        }
    }
}
